﻿<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             x:Class="TimeZoneTest.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
             xmlns:System="clr-namespace:System;assembly=mscorlib"
             xmlns:local="clr-namespace:TimeZoneTest.ViewModel"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="531">
   <sdk:TabControl>
      <sdk:TabItem Header="CRM 2011 TimeZone conversion use case">
         <Grid x:Name="LayoutRoot"
               Background="White"
               DataContext="{StaticResource CrmViewModel}">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="378*" />
               <ColumnDefinition Width="22*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
               <RowDefinition Height="auto" />
					<RowDefinition Height="auto" />
               <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Margin="10">
               <ComboBox ItemsSource="{Binding AvailableTimeZones}"
                         DisplayMemberPath="UserInterfaceName"
                         MinWidth="300"
                         SelectedItem="{Binding SelectedTimeZone, Mode=TwoWay}"></ComboBox>
               <Button Content="Get all time zones from CRM"
                       Padding="5"
                       Margin="200, 0,0,0"
                       Click="ButtonBase_OnClick"
							  
                       Command="{Binding GetZonesCommand}" />
            </StackPanel>
            <StackPanel Grid.Row="1"
                        Grid.ColumnSpan="2"  Margin="10">
               <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Time Zone Code:" />
                  <TextBlock Text="{Binding SelectedTimeZone.TimeZoneCode}" />
                  <TextBlock Text="       Time Zone Name: " />
                  <TextBlock Text="{Binding SelectedTimeZone.UserInterfaceName}" />
               </StackPanel>
               <sdk:DataGrid VerticalScrollBarVisibility="Auto"
                             HorizontalScrollBarVisibility="Auto"
                             ItemsSource="{Binding SelectedTimeZone.TimeZoneRules}" />
            </StackPanel>
            <StackPanel Grid.Row="2"
                        Orientation="Vertical"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Bottom"
                        Grid.ColumnSpan="2"  Margin="10">
               <StackPanel Orientation="Horizontal"
                           HorizontalAlignment="Stretch"
                           VerticalAlignment="Bottom"
                           Margin="5">
                  <StackPanel.Resources>
                     <local:StaticSurrogate x:Key="Static" />
                     <local:Formatter x:Key="Formatter" />
                  </StackPanel.Resources>
                  <TextBlock FontWeight="Bold"> &#160;&#160;&#160;&#160; CRM time is:&#160;</TextBlock>
                  <TextBlock  Text="{Binding SelectedTimeZone.Now, Converter={StaticResource Formatter}, ConverterParameter='dd MMM yyy hh:mm tt'}"></TextBlock>
                  <TextBlock FontWeight="Bold">&#160;&#160;&#160;&#160; PC time is:&#160;</TextBlock>
                  <TextBlock  Text="{Binding Path=Now, Source={StaticResource Static},Converter={StaticResource Formatter}, ConverterParameter='dd MMM yyy hh:mm tt'}"></TextBlock>
                  <TextBlock FontWeight="Bold"> &#160;&#160;&#160;&#160; UTC time is:&#160;</TextBlock>
                  <TextBlock  Text="{Binding Path=UTCNow, Source={StaticResource Static}, Converter={StaticResource Formatter}, ConverterParameter='dd MMM yyy hh:mm tt'}"></TextBlock>
               </StackPanel>
               <Grid>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                     <RowDefinition />
                     <RowDefinition />
                     <RowDefinition />
                     <RowDefinition />
                  </Grid.RowDefinitions>
                  <TextBlock Margin="5"
                             VerticalAlignment="Center">UTC time :&#160;</TextBlock>
                  <sdk:DatePicker  Margin="5"
                                   Grid.Column="1"
                                   SelectedDate="{Binding UTCDateTime, Mode=TwoWay}" />
                  <toolkit:TimePicker  Margin="5"
                                       Grid.Column="2"
                                       Value="{Binding UTCDateTime, Mode=TwoWay }" />
                  <TextBlock  Margin="5"
                              Grid.Column="3"
                              VerticalAlignment="Center">&#160; in CRM time zone will be :&#160;</TextBlock>
                  <TextBlock  Margin="5"
                              Grid.Column="4"
                              VerticalAlignment="Center"
                              Text="{Binding UTCTime, StringFormat='dd.MM.yyyy hh:mm tt'}" />
                  <TextBlock  Margin="5"
                              Grid.Row="1"
                              VerticalAlignment="Center">PC local time:&#160;</TextBlock>
                  <sdk:DatePicker  Margin="5"
                                   Grid.Row="1"
                                   Grid.Column="1"
                                   SelectedDate="{Binding PCDateTime, Mode=TwoWay}" />
                  <toolkit:TimePicker  Margin="5"
                                       Grid.Row="1"
                                       Grid.Column="2"
                                       Value="{Binding PCDateTime, Mode=TwoWay }" />
                  <TextBlock  Margin="5"
                              Grid.Row="1"
                              Grid.Column="3"
                              VerticalAlignment="Center">&#160; in CRM time zone will be :&#160;</TextBlock>
                  <TextBlock  Margin="5"
                              Grid.Row="1"
                              Grid.Column="4"
                              VerticalAlignment="Center"
                              Text="{Binding PCTime, StringFormat='dd.MM.yyyy hh:mm tt'}" />
                  <TextBlock  Margin="5"
                              Grid.Row="2"
                              Grid.ColumnSpan="4"
                              VerticalAlignment="Center">Time in UTC format that we have to send to CRM if we want to save time user input above in local PC time:</TextBlock>
                  <TextBlock  Margin="5"
                              Grid.Row="3"
                              Grid.ColumnSpan="4"
                              VerticalAlignment="Center"
                              Text="{Binding RealUTCTime, StringFormat='dd.MM.yyyy hh:mm tt'}" />
               </Grid>
            </StackPanel>
         </Grid>
      </sdk:TabItem>
   </sdk:TabControl>
</UserControl>
